package top.hudk.sort;

import java.util.ArrayList;
import java.util.List;

/**
 * 作用：
 *
 * @author hudk
 * @date 2020/11/3 17:04
 */
public class test {


    public static void main(String[] args){

        System.out.println(System.currentTimeMillis());
        List<Object> list = new ArrayList<>();
//        int[] arr = new int[]{6, 2, 15, 9, 1};
//        quickSork(arr,0,arr.length-1);
//        for(int i=0;i < arr.length; i++){
//            System.out.println(arr[i]);
//        }
    }


    public void sort(int[] arr,int left,int right,int[] temp){

        if(left < right){
            int mid = (right - left) / 2;
            sort(arr,left,mid,temp);
            sort(arr,mid,right,temp);
            merge(arr,left,mid,right,temp);
        }
    }


    public void merge(int[] arr, int left,int mid, int right,int[] temp){

        int tempIndex=0;
        int l = left;
        int r = mid + 1;
        while (l <= mid && r <= right){
            if(arr[l] < arr[r]){
                temp[tempIndex++] = arr[l++];
            }else {
                temp[tempIndex++] = arr[r++];
            }
        }
        while (l <= mid){
            temp[tempIndex++] = arr[l++];
        }
        while (r <= right){
            temp[tempIndex++] = arr[r++];
        }
        for(int t = 0; t < tempIndex; t++ ){
            arr[left + t] = temp[t];
        }
    }

}



